package handler

import (
	"context"
	"gozero-microservices/gateway-api/internal/logic"
	"gozero-microservices/gateway-api/utils"
	"net/http"
	"strconv"
)

/*
 +----------------------------------------------------------------------
 + Title        : UserDeliveryAddrHandler
 + Author       : huwl
 + Version      : 1.0.0
 + Initial-Time : 2025-08-08
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 用户收货地址处理器
 +----------------------------------------------------------------------
*/

type UserDeliveryAddrHandler struct {
	BaseHandler
}

/**
 * 详情
 *
 * @param int id ------------------------------必传,Id
 * @return json
 * @author huwl
 * @date 2025/10/22 10:15:55
 */
func (control *UserDeliveryAddrHandler) Detail(w http.ResponseWriter, r *http.Request) {
	id, _ := strconv.Atoi(utils.DefaultQuery(r, "id", "0"))

	// 调用逻辑层
	udal := logic.NewUserDeliveryAddrLogicInstance(context.Background(), control.SvcCtx)
	result, err := udal.Detail(uint64(id))
	if err != nil {
		control.BaseError(r, w, control.WithGrpcError(err))
		return
	}

	control.BaseSuccess(r, w, control.WithData(result.UserDeliveryAddr))
}
